//
//  HWSaveMoneyCardProtocol.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/6/29.
//  Copyright © 2022 94hwan. All rights reserved.
//

import UIKit

class HWSaveMoneyCardProtocol: NSObject {
    var model:HWSaveModeyCardModel?
    
    var selectButtonClick:(()->())?
    var payButtonClick:((_:String,_:String)->())?
    var bottomButtonClick:((_:String,_:String)->())?
}
extension HWSaveMoneyCardProtocol: UITableViewDelegate,UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        if model != nil {
            return 4
        }
        return 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let topCell = HWSaveMoneyCardTopCell.cellWithTableView(tableView: tableView)
        let couponCell = HWSaveMoneyCardCouponCell()
        let createCell = HWSaveMoneyCardCreateCell.cellWithTableView(tableView: tableView)
        let explainCell = HWSaveMoneyExplainCell.cellWithTableView(tableView: tableView)
        if indexPath.section == 0 {
            topCell.model = model
            return topCell
        } else if indexPath.section == 1 {
            couponCell.model = model
            couponCell.bottomButtonClick = {
                self.bottomButtonClick?($0,$1)
            }
            return couponCell
        } else if indexPath.section == 2 {
            createCell.model = model
            createCell.selectButtonClick = {
                self.selectButtonClick?()
            }
            createCell.payButtonClick = {
                self.payButtonClick?($0,self.model?.selectZhou == true ? "3":"4")
            }
            
            return createCell
        } else if indexPath.section == 3 {
            explainCell.model = model
            return explainCell
        }
        return topCell
    }
    
}
